package com.alibaba.aone.casestudy.module.action;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.aone.casestudy.common.entity.ActionConditions;
import com.alibaba.aone.casestudy.common.entity.Action;

import com.alibaba.aone.casestudy.service.ActionService;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param;

/**
 * 类ActionListAction.java的实现描述：TODO 类实现描述 
 * @author yongchun.chengyc 2011-4-29 上午09:47:35
 */
public class ActionListAction {
	@Autowired
	private ActionService actionService;

	public void doSearch(
			@Param("cgDepartment")String cgDepartment,
			@Param("chargeMan")String chargeMan,
			@Param("follower")String follower,
			@Param("department")String department,
			@Param("status")Integer[] statusArray,
			@Param("category")Integer[] categoryArray,
			@Param("latestCompleteTimeFrom")String latestCompleteTimeFromTemp,
			@Param("latestCompleteTimeTo")String latestCompleteTimeToTemp,
			@Param("realCompleteTimeFrom")String realCompleteTimeFromTemp,
			@Param("realCompleteTimeTo")String realCompleteTimeToTemp,
			Context context) throws ParseException{
		ActionConditions actionConditions=  new ActionConditions();
		List<Integer> statuses = new ArrayList<Integer>();
		statuses.addAll(Arrays.asList(statusArray));
		List<Integer> categories = new ArrayList<Integer>();
		categories.addAll(Arrays.asList(categoryArray));
		
		
		Date latestCompleteTimeFrom =null;
		Date latestCompleteTimeTo =null;
		Date realCompleteTimeFrom =null;
		Date realCompleteTimeTo =null;
	
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println("<------------------------------------------------------->");
		System.out.println(chargeMan);
		System.out.println(follower);
		System.out.println(latestCompleteTimeFrom);
		System.out.println(latestCompleteTimeTo);
		System.out.println(realCompleteTimeFrom);
		System.out.println(realCompleteTimeTo);
		System.out.println("<------------------------------------------------------->");
		
		latestCompleteTimeFrom = StringUtils.isEmpty(latestCompleteTimeFromTemp) ? null:format.parse(latestCompleteTimeFromTemp);
		latestCompleteTimeTo = StringUtils.isEmpty(latestCompleteTimeToTemp) ? null:format.parse(latestCompleteTimeToTemp);
		realCompleteTimeFrom = StringUtils.isEmpty(realCompleteTimeFromTemp) ? null:format.parse(realCompleteTimeFromTemp);
		realCompleteTimeTo = StringUtils.isEmpty(realCompleteTimeToTemp) ? null:format.parse(realCompleteTimeToTemp);
	
		System.out.println("<------------------------------------------------------->");
		System.out.println(chargeMan);
		System.out.println(follower);
		System.out.println(latestCompleteTimeFrom);
		System.out.println(latestCompleteTimeTo);
		System.out.println(realCompleteTimeFrom);
		System.out.println(realCompleteTimeTo);
		System.out.println("<------------------------------------------------------->");
		
		
		actionConditions.setCgDepartment(cgDepartment);
		actionConditions.setChargeMan(chargeMan);
		actionConditions.setFollower(follower);
		actionConditions.setDepartment(department);
		actionConditions.setCategories(categories);
		actionConditions.setStatuses(statuses);
		actionConditions.setLatestCompleteTimeFrom(latestCompleteTimeFrom);
		actionConditions.setLatestCompleteTimeTo(latestCompleteTimeTo);
		actionConditions.setRealCompleteTimeFrom(realCompleteTimeFrom);
		actionConditions.setRealCompleteTimeTo(realCompleteTimeTo);
		
		
		List<Action> actions = actionService.search(actionConditions);
		
		context.put("actions",actions);
		
		
	}
}
